home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Mac OS X Throbber / Source / Documents / MultiMonitorDoc.cp next >
Text File  |  2000-06-23  |  6KB  |  214 lines

  1. #include "MultiMonitorDoc.h"
  2.  
  3. #include <PP_DebugMacros.h>
  4. #include <PP_KeyCodes.h>
  5.  
  6. #include <LFile.h>
  7. #include <LPlaceHolder.h>
  8. #include <LCheckBoxGroupBox.h>
  9. #include <LPopupButton.h>
  10. #include <LPrintout.h>
  11. #include <LString.h>
  12. #include <LSlider.h>
  13. #include <LWindow.h>
  14. #include <PP_Messages.h>
  15. #include <UMemoryMgr.h>
  16. #include <UResourceMgr.h>
  17. #include <UWindows.h>
  18.  
  19. #include <AERegistry.h>
  20.  
  21. #include "AppConstants.h"
  22. #include "MultiMonitorController.h"
  23.  
  24. const PaneIDT    kPaneID_MMEnable            = 'MMEn';
  25. const PaneIDT    kPaneID_MMEffects            = 'MMEf';
  26. const PaneIDT    kPaneID_MMSettings1            = 'MMS1';
  27. const PaneIDT    kPaneID_MMSettings2            = 'MMS2';
  28.  
  29. const MessageT    msg_MMEnable                = 'MMEn';
  30. const MessageT    msg_MMEffects                = 'MMEf';
  31. const MessageT    msg_MMSettings1                = 'MMS1';
  32. const MessageT    msg_MMSettings2                = 'MMS2';
  33.  
  34.  
  35. // ---------------------------------------------------------------------------------
  36. //    • MultiMonitorDoc                                        [public]
  37. // ---------------------------------------------------------------------------------
  38. //    Constructor
  39.  
  40. MultiMonitorDoc::MultiMonitorDoc(
  41.     LCommander *        inSuper)
  42.     : LSingleDoc(inSuper)
  43. {
  44.         // Create window for our document.
  45.     mWindow = LWindow::CreateWindow(PPob_TextWindow, this );
  46.     ValidateObject_(mWindow);
  47.     
  48.     LPane *     newPane;
  49.     
  50.     newPane = mWindow->FindPaneByID(kPaneID_MMEnable);
  51.     ValidateObject_(newPane);
  52.     static_cast<LCheckBoxGroupBox *>(newPane)->AddListener(this);
  53.  
  54.     newPane = mWindow->FindPaneByID(kPaneID_MMEffects);
  55.     ValidateObject_(newPane);
  56.     static_cast<LPopupButton *>(newPane)->AddListener(this);
  57.  
  58.     newPane = mWindow->FindPaneByID(kPaneID_MMSettings1);
  59.     ValidateObject_(newPane);
  60.     static_cast<LSlider *>(newPane)->AddListener(this);
  61.  
  62.     newPane = mWindow->FindPaneByID(kPaneID_MMSettings2);
  63.     ValidateObject_(newPane);
  64.     static_cast<LSlider *>(newPane)->AddListener(this);
  65.  
  66.         // Make the window visible.
  67.     mWindow->Show();
  68. }
  69.  
  70.  
  71. // ---------------------------------------------------------------------------------
  72. //    • ~MultiMonitorDoc                                    [public, virtual]
  73. // ---------------------------------------------------------------------------------
  74. //    Destructor
  75.  
  76. MultiMonitorDoc::~MultiMonitorDoc()
  77. {
  78.     MultiMonitorController &    mmController = MultiMonitorController::GetInstance();
  79.  
  80.     // Disable the multi-monitor controller before
  81.     // going away.
  82.     mmController.Disable();
  83.  
  84.     TakeOffDuty();
  85. }
  86.  
  87.  
  88. // ---------------------------------------------------------------------------
  89. //    • FindCommandStatus                                    [public, virtual]
  90. // ---------------------------------------------------------------------------
  91. //    Override provided here for convenience.
  92.  
  93. void
  94. MultiMonitorDoc::FindCommandStatus(
  95.     CommandT        inCommand,
  96.     Boolean&        outEnabled,
  97.     Boolean&        outUsesMark,
  98.     UInt16&            outMark,
  99.     Str255            outName)
  100. {
  101.     LSingleDoc::FindCommandStatus(inCommand, outEnabled, outUsesMark, outMark, outName);    
  102. }
  103.  
  104.  
  105. // ---------------------------------------------------------------------------
  106. //    • ListenToMessage                                    [public, virtual]
  107. // ---------------------------------------------------------------------------
  108.  
  109. void
  110. MultiMonitorDoc::ListenToMessage(
  111.     MessageT        inMessage,
  112.     void*            ioParam)
  113. {
  114.     SInt32                        controlValue = *reinterpret_cast<SInt32 *>(ioParam);
  115.     MultiMonitorController &    mmController = MultiMonitorController::GetInstance();
  116.     
  117.     switch (inMessage)
  118.     {
  119.         case msg_MMEnable:
  120.             if (controlValue == 0)
  121.                 mmController.Disable();
  122.             else
  123.                 mmController.Enable();
  124.             break;
  125.         
  126.         case msg_MMEffects:
  127.             mmController.SetEffectsType(controlValue - 1);
  128.  
  129.             LSlider *                    slider1;
  130.             LSlider *                    slider2;
  131.             slider1 = static_cast<LSlider *>(mWindow->FindPaneByID(kPaneID_MMSettings1));
  132.             slider2 = static_cast<LSlider *>(mWindow->FindPaneByID(kPaneID_MMSettings2));
  133.             
  134.             if (slider1 != NULL)
  135.                 slider1->SetValue(0);
  136.             if (slider2 != NULL)
  137.                 slider2->SetValue(0);
  138.             break;
  139.         
  140.         case msg_MMSettings1:
  141.         case msg_MMSettings2:
  142.             mmController.SetEffectsValue(inMessage - msg_MMSettings1, (double)controlValue / 100.0);
  143.             break;
  144.     }
  145. }
  146.  
  147.  
  148. // ---------------------------------------------------------------------------
  149. //    • ProcessKeyPress
  150. // ---------------------------------------------------------------------------
  151.  
  152. Boolean
  153. MultiMonitorDoc::HandleKeyPress(
  154.     const EventRecord&    inKeyEvent)
  155. {
  156.     Boolean                        handled = false;
  157.     MultiMonitorController &    mmController = MultiMonitorController::GetInstance();
  158.     LSlider *                    slider1;
  159.     LSlider *                    slider2;
  160.  
  161.     slider1 = static_cast<LSlider *>(mWindow->FindPaneByID(kPaneID_MMSettings1));
  162.     slider2 = static_cast<LSlider *>(mWindow->FindPaneByID(kPaneID_MMSettings2));
  163.     
  164.     if (slider1 != NULL && slider2 != NULL)
  165.     {
  166.         // Allow user to control sliders through command-arrows
  167.         if (inKeyEvent.modifiers & cmdKey)
  168.         {
  169.             switch (inKeyEvent.message & charCodeMask)
  170.             {
  171.                 case char_LeftArrow:
  172.                     slider1->SetValue(slider1->GetValue() - 1);
  173.                     handled = true;
  174.                     break;
  175.                 
  176.                 case char_RightArrow:
  177.                     slider1->SetValue(slider1->GetValue() + 1);
  178.                     handled = true;
  179.                     break;
  180.                 
  181.                 case char_DownArrow:
  182.                     slider2->SetValue(slider2->GetValue() + 1);
  183.                     handled = true;
  184.                     break;
  185.                 
  186.                 case char_UpArrow:
  187.                     slider2->SetValue(slider2->GetValue() - 1);
  188.                     handled = true;
  189.                     break;
  190.             }
  191.         }
  192.     }
  193.     
  194.     return handled;
  195. }
  196.  
  197.  
  198. // ---------------------------------------------------------------------------
  199. //    • ObeyCommand                                        [public, virtual]
  200. // ---------------------------------------------------------------------------
  201. //    Override provided here for convenience.
  202.  
  203. Boolean
  204. MultiMonitorDoc::ObeyCommand(
  205.     CommandT        inCommand,
  206.     void*            ioParam)
  207. {
  208.     Boolean    cmdHandled = LSingleDoc::ObeyCommand(inCommand, ioParam);
  209.  
  210.     return cmdHandled;
  211. }
  212.  
  213.  
  214.